<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <script src="js/mui.min.js"></script>
    <link href="css/mui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="css/header.css" />
    <script type="text/javascript" charset="utf-8">
      	mui.init();
      	
      	mui.plusReady(function() {
      		plus.navigator.setStatusBarStyle("light");
      		plus.navigator.setStatusBarBackground("blanchedalmond");
      	});
    </script>
</head>
<body>
	<header class="mui-bar mui-bar-nav title">
	    <h1 class="mui-title title-color"><b id="b_header">缘信<b></h1>
	</header>
	<nav class="mui-bar mui-bar-tab">
	    <a class="mui-tab-item mui-active" tabIndex = "0">
	        <span class="mui-icon mui-icon-weixin"></span>
	        <span class="mui-tab-label">缘信</span>
	    </a>
	    <a class="mui-tab-item" tabIndex = "1">
	        <span class="mui-icon mui-icon-phone"></span>
	        <span class="mui-tab-label">通讯录</span>
	    </a>
	    <a class="mui-tab-item" tabIndex = "2">
	        <span class="mui-icon mui-icon-paperplane"></span>
	        <span class="mui-tab-label">发现</span>
	    </a>
	    <a class="mui-tab-item" tabIndex = "3">
	        <span class="mui-icon mui-icon-person"></span>
	        <span class="mui-tab-label">我的</span>
	    </a>
	</nav>
	
	
	<script type="application/javascript">
		var tyArray = [
			{
				pageId:"chatList.html",
				pageUrl:"/html/chatList/chatList.html"
			},
			{
				pageId:"contact.html",
				pageUrl:"/html/contact/contact.html"
			},
			{
				pageId:"discover.html",
				pageUrl:"/html/direction/discover.html"
			},
			{
				pageId:"myHome.html",
				pageUrl:"/html/myself/myHome.html"
			}
		];
		
		var tyStyle = {
			top : "44px",
			bottom: "50px"
			
		};
		
		mui.plusReady(function() {
			
			//禁止后退
			mui.back = function() {
				return false;
			}
			
			//检测网络连接
			netChangeSwitch();
			
			var indexWebview = plus.webview.currentWebview();
			
			for (var i = 0;i < tyArray.length; i++) {
				var tyPage = plus.webview.create(tyArray[i].pageUrl, tyArray[i].pageId, tyStyle);
				tyPage.hide();
				indexWebview.append(tyPage);
			}
			plus.webview.show(tyArray[0].pageId);
			
			
			//批量绑定tap事件，展示页面
			mui(".mui-bar-tab").on("tap", "a", function() {
				var tabIndex = this.getAttribute("tabIndex");
				plus.webview.show(tyArray[tabIndex].pageId, "fade-in", 100);
				for (var i = 0;i < tyArray.length; i++) {
					if(i != tabIndex) {
						plus.webview.hide(tyArray[i].pageId, "fade-out", 100);
					}
				}
			});
			
		});
		
		//检测网络连接
		function netChangeSwitch() {
			document.addEventListener("netchange", function() {
				var networkType = plus.networkinfo.getCurrentType();
				var b_header = document.getElementById("b_header");
				if(networkType != 0 && networkType != 1) {
					b_header.innerHTML = "缘信";
				} else {
					b_header.innerHTML = "缘信(未连接网络...)";
				}
			});
		}
	</script>
</body>
</html>